require( '$d/css/common.less' );
require( '$d/js/modules/header/style.less' );
require( './style.less' );
define( [
  'jquery',
  'require',
  'message',
  'api',
  'bootstrap',
  'bigwe_utils'
], function( $, require ) {
  var ShowTitleMessage = require( 'message' ),
    showTime = ShowTitleMessage.showTime,
    BIGWE_API = require( 'api' ),
    getUrlParam = require( 'bigwe_utils' ).getUrlParam;
  // var _zxcvbnSettings = {"src":"Public\/static\/js\/common\/zxcvbn.min.js"};
  //邮箱验证
  var emailRe = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  //手机号验证
  var re = /^1[3,4,5,7,8]{1}[0-9]{9}$/;
  //验证码验证
  var codeRe = /^[A-Za-z0-9]{6}$/;
  //密码验证
  var pwdRe = /^[a-zA-Z0-9_\.\-]{6,20}$/;



  $( function() {
    //验证码刷新
    $( '.verify_img img' ).click( function() {
      $( ".verify_img img" ).attr( "src", "/RegisterPage/captcha" );
    } );
    //邀请链接过来样式
    if ( getUrlParam( window.location.search, 'search_type' ) != null ) {
      $( '.user_invitation' ).val( getUrlParam( window.location.search, 'search_type' ) );
      $( '.user_invitation' ).attr( 'readonly', 'readonly' );
      $( '.user_invitation' ).css( 'background', '#c7c7c7' );
    }
    //微知协议勾选
    $( ".checkbox" ).change( function() {
      if ( $( this ).prop( "checked" ) ) {
        $( '#phone_button' ).removeAttr( 'disabled' );
      } else $( '#phone_button' ).prop( "disabled", "disabled" );
    } )

    //邮箱登陆跳转链接数组
    var hash = {
      'qq.com': 'http://mail.qq.com',
      'gmail.com': 'http://mail.google.com',
      'sina.com': 'http://mail.sina.com.cn',
      '163.com': 'http://mail.163.com',
      '126.com': 'http://mail.126.com',
      'yeah.net': 'http://www.yeah.net/',
      'sohu.com': 'http://mail.sohu.com/',
      'tom.com': 'http://mail.tom.com/',
      'sogou.com': 'http://mail.sogou.com/',
      '139.com': 'http://mail.10086.cn/',
      'hotmail.com': 'http://www.hotmail.com',
      'live.com': 'http://login.live.com/',
      'live.cn': 'http://login.live.cn/',
      'live.com.cn': 'http://login.live.com.cn',
      '189.com': 'http://webmail16.189.cn/webmail/',
      'yahoo.com.cn': 'http://mail.cn.yahoo.com/',
      'yahoo.cn': 'http://mail.cn.yahoo.com/',
      'eyou.com': 'http://www.eyou.com/',
      '21cn.com': 'http://mail.21cn.com/',
      '188.com': 'http://www.188.com/',
      'foxmail.com': 'http://www.foxmail.com'
    };
    //手机号邮箱注册操作
    $( ".login-list" ).on( "click", "#phone_button", function() {
      var phone = $( "#user_phone" ).val();
      var code = $( "#verify_code" ).val();
      if ( $( '#user_phone' ).val() == '' ) {
        $( '.fontred_phone' ).html( '账号不能为空' );
        $( '.fontred_phone' ).parent().addClass( 'error' ).next().addClass( 'active' ).find( '.text' ).text( '账号不能为空' );
        $( '.phone_right' ).hide();
        return;
      }
      if ( $( '#verify_code' ).val() == '' ) {
        $( '.fontred_verify' ).html( '请输入手机验证码' );
        $( '.fontred_verify' ).parent().addClass( 'error' ).next().next().addClass( 'active' ).find( '.text' ).text( '请输入手机验证码' );
        $( '.verify_right' ).hide();
        return;
      }
      if ( $( '#phone_user_name' ).val() == '' ) {
        $( '#phone_user_name' ).siblings( '.name_right' ).hide();
        $( '#phone_user_name' ).siblings( '.fontred_name' ).html( '微知名称不能为空' );
        $( '#phone_user_name' ).siblings( '.fontred_name' ).parent().addClass( 'error' ).next().addClass( 'active' ).find( '.text' ).text( '微知名称不能为空' );
        return;
      }
      if ( $( '#phone_user_pwd' ).val() == '' ) {
        $( '#phone_user_pwd' ).siblings( '.pwd_right' ).hide();
        $( '#phone_user_pwd' ).siblings( '.fontred_pwd' ).html( '密码不能为空' );
        $( '#phone_user_pwd' ).siblings( '.fontred_pwd' ).parent().addClass( 'error' ).next().addClass( 'active' ).find( '.text' ).text( '密码不能为空' );
        return;
      }
      if ( $( '#phone_user_invitation' ).val() == '' ) {
        $( '#phone_user_invitation' ).parent().addClass( 'error' ).next().addClass( 'active' ).find( '.text' ).text( '邀请码不能为空' );
        return;
      }
      /*var _text=$('.register-phone .item .fontred_warning').text();
      if(_text!=''){
          return;
      }*/
      //手机号、昵称、邀请码验证
      $.ajax( {
        type: "POST", //用POST方式传输
        dataType: 'text',
        url: BIGWE_API.REGISTER.NICENAME_VERIFY, //目标地址
        data: {
          user_name: $( '#phone_user_name' ).val()
        },
        success: function( msg ) {
          if ( msg == 'success' ) {
            //手机号
            $.ajax( {
              cache: true,
              type: "POST", //用POST方式传输
              dataType: 'json',
              url: BIGWE_API.REGISTER.VERIFY_VALID_CODE, //目标地址
              data: {
                account: phone,
                valid_code: code
              },
              error: function() {
                ShowTitleMessage.showWarning( '手机号/邮箱查询失败', showTime );
              },
              success: function( data ) {
                if ( data.ret == 0 ) {
                  $( '.fontred_verify' ).html( '' );
                  $( '.verify_right' ).show();
                  //邀请码
                  if ( $( '.user_invitation' ).val() != '' ) {
                    $.ajax( {
                      cache: true,
                      type: "POST", //用POST方式传输
                      dataType: 'text',
                      url: BIGWE_API.REGISTER.INVITATION_VERIFY, //目标地址
                      data: {
                        user_invitation: $( '.user_invitation' ).val()
                      },
                      error: function() {
                        ShowTitleMessage.showWarning( '输入的邀请码有误', showTime );
                      },
                      success: function( msg ) {
                        switch ( msg ) {
                          case 'error_invitation_null':
                            $( '.fontred_invitation' ).html( '邀请码无效' );
                            $( '#phone_user_invitation' ).parent().addClass( 'error' ).next().addClass( 'active' ).find( '.text' ).text( '邀请码无效' );
                            $( '.invitation_right' ).hide();
                            break;
                          case 'error_invitation_invalid':
                            $( '.fontred_invitation' ).html( '邀请码失效' );
                            $( '#phone_user_invitation' ).parent().addClass( 'error' ).next().addClass( 'active' ).find( '.text' ).text( '邀请码失效' );
                            $( '.invitation_right' ).hide();
                            break;
                          default:
                            $( '.invitation_right' ).show();
                            //手机号注册
                            $.ajax( {
                              cache: true,
                              type: "POST", //用POST方式传输
                              dataType: 'text',
                              url: BIGWE_API.REGISTER.REGISTER_VERIFY, //目标地址
                              data: {
                                account: $( '#user_phone' ).val(),
                                user_name: $( '#phone_user_name' ).val(),
                                user_pwd: $( '#phone_user_pwd' ).val(),
                                user_invitation: $( '#phone_user_invitation' ).val(),
                                valid_code: code,
                              },
                              error: function( msg ) {
                                ShowTitleMessage.showWarning( '注册失败', showTime );
                              },
                              success: function( msg ) {
                                msg = eval( '(' + msg + ')' );
                                if ( msg[ 'ret' ] == 0 ) {
                                  location.href = '/'
                                } else {
                                  ShowTitleMessage.showWarning( msg[ 'msg' ], showTime );
                                }
                              }
                            } );
                        }
                      }
                    } );
                  }
                  /*else{
                          //手机号注册
                          $.ajax({
                              cache: true,
                              type: "POST",                     //用POST方式传输
                              dataType: 'text',
                              url: BIGWE_API.REGISTER.REGISTER_VERIFY,      //目标地址
                              data: {
                                  account         :   $('#user_phone').val(),
                                  user_name       :   $('#phone_user_name').val(),
                                  user_pwd        :   $('#phone_user_pwd').val(),
                                  user_invitation :   $('#phone_user_invitation').val(),
                                  valid_code      :   code,
                              },
                              error: function (msg) {
                                  ShowTitleMessage.showWarning('注册失败', showTime);
                              },
                              success: function (msg) {
                                  msg = apinput(msg);
                                  if(msg=='ok'){
                                      location.href = '/'
                                  }
                              }
                          });
                      }*/
                } else {
                  $( '.verify_right' ).hide();
                  $( '.fontred_verify' ).parent().addClass( 'error' ).next().next().addClass( 'active' ).find( '.text' ).text( data.msg );
                  //$('.fontred_verify').html(data.msg);
                }
              }
            } );
          } else {
            $( '.name_right' ).hide();
            //$('.register-phone .fontred_name').html('该昵称已被使用');
            $( '#phone_user_name' ).siblings( '.fontred_name' ).parent().addClass( 'error' ).next().addClass( 'active' ).find( '.text' ).text( '微知名称已被使用' );
          }
        }
      } );

    } );

    //手机号内容鼠标检测
    $( '#user_phone' ).blur( function() {
      var $msgbox = $( this ).parent().addClass( 'error' ).next();
      if ( $( '#user_phone' ).val() == '' ) {
        $( '.fontred_phone' ).html( '账号不能为空' );
        $( '.phone_right' ).hide();
        // sherlock
        $msgbox.addClass( 'active' ).find( '.text' ).text( '账号不能为空' );
      } else {
        if ( re.test( $( '#user_phone' ).val() ) || emailRe.test( $( '#user_phone' ).val() ) ) {
          $( '.fontred_phone' ).html( '' );
          //$('.phone_right').show();
          // sherlock
          $msgbox.removeClass( 'active' );
          $( this ).parent().removeClass( 'error' );
        } else {
          $( '.fontred_phone' ).html( '输入的手机号 / 邮箱有误' );
          $( '.phone_right' ).hide();
          $msgbox.addClass( 'active' ).find( '.text' ).text( '输入的手机号 / 邮箱有误' );
        }
      }
    } );
    //手机号内容键盘检测
    /*$('#user_phone').keyup(function(){
        if($('#user_phone').val()==''){
            $('.fontred_phone').html('必填项');
            $('.phone_right').hide();

        }else{
            if(re.test($('#user_phone').val())||emailRe.test($('#user_phone').val())){
                
                $('.fontred_phone').html('');
                //$('.phone_right').show();
            }
            else{
                $('.fontred_phone').html('输入的手机号 / 邮箱有误');
                $('.phone_right').hide();
            }
        }
    });*/

    //验证码内容鼠标检测
    $( '#verify_code' ).blur( function() {
      var $msgbox = $( this ).parent().addClass( 'error' ).next();
      //var $msgbox = $('.js_verify_code');
      if ( $( '#verify_code' ).val() == '' ) {
        $( '.fontred_verify' ).html( '验证码不能为空' );
        $( '.verify_right' ).hide();

        $msgbox.next().addClass( 'active' ).find( '.text' ).text( '验证码不能为空' );

      } else {
        if ( !codeRe.test( $( '#verify_code' ).val() ) ) {
          $( '.fontred_verify' ).html( '输入的验证码格式有误' );
          $( '.verify_right' ).hide();
          $msgbox.next().addClass( 'active' ).find( '.text' ).text( '输入的验证码格式有误' );
        } else {
          $( '.fontred_verify' ).html( '' );
          //$('.verify_right').show();
          $msgbox.next().removeClass( 'active' );
          $( this ).parent().removeClass( 'error' );
        }
      }
    } );
    //验证码内容键盘检测
    /*$('#verify_code').keyup(function(){
        if($('#verify_code').val()==''){
            $('.fontred_verify').html('必填项');
            $('.verify_right').hide();
        }
        else{
            if(!codeRe.test($('#verify_code').val())){
                $('.verify_right').hide();
                $('.fontred_verify').html('输入的验证码有误');
            }
            else{
                $('.fontred_verify').html('');
            }
        }
    });*/

    //昵称内容的键盘检测
    $( '.user_name' ).blur( function() {
      var $msgbox = $( this ).parent().addClass( 'error' ).next().removeClass( 'active msg' );
      var $_box = $( this ).parent();
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.name_right' ).hide();
        $( this ).siblings( '.fontred_name' ).html( '微知名称不能为空' );
        // sherlock
        $msgbox.addClass( 'active' ).find( '.error_text .text' ).text( '微知名称不能为空' );
      } else {
        if ( $( this ).val().length >= 2 && chkstrlen( $( this ).val() ) <= 20 ) {
          $.ajax( {
            type: "POST", //用POST方式传输
            dataType: 'text',
            url: BIGWE_API.REGISTER.NICENAME_VERIFY, //目标地址
            data: {
              user_name: $( '#phone_user_name' ).val()
            },
            success: function( msg ) {
              if ( msg == 'success' ) {
                $( '.register-phone .name_right' ).show();
                $msgbox.removeClass( 'active' );
                $_box.removeClass( 'error' );
              } else {
                $( '.name_right' ).hide();
                $( '.register-phone .fontred_name' ).html( '该昵称已被使用' );
                $msgbox.addClass( 'active' ).find( '.error_text .text' ).text( '该昵称已被使用' );
              }
            }
          } );
        } else {
          $msgbox.addClass( 'active' ).find( '.text' ).text( '输入的名称格式有误' );
        }
      }
    } ).focus( function() {
      $( this ).parent().addClass( 'error' ).next().addClass( 'active msg' );
    } );;
    /*$('.user_name').keyup(function(){
        if($(this).val()==''){
            $(this).siblings('.name_right').hide();
            $(this).siblings('.fontred_name').html('必填项');           
        }
        else{
            if($(this).val().length < 2){
                $(this).siblings('.name_right').hide();
                $(this).siblings('.fontred_name').html('输入的名称格式有误');
            }
            else if(chkstrlen($(this).val()) > 20){
                $(this).siblings('.name_right').hide();
                $(this).siblings('.fontred_name').html('输入的名称格式有误');
            }else{
                $(this).siblings('.fontred_name').html('');
            }
        }
    });*/

    //用户密码内容的键盘检测
    $( '.user_pwd' ).focus( function() {
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.fontred_pwd' ).html( '' );
        $( '.login-list .focus_tips' ).show();
      }
      $( this ).parent().addClass( 'error' ).next().addClass( 'active msg' );
    } ).blur( function() {
      var $msgbox = $( this ).parent().next().removeClass( 'active msg' );
      $( '.login-list .focus_tips' ).hide();
      if ( $( this ).val() == '' ) {
        $( this ).siblings( '.pwd_right' ).hide();
        $( this ).siblings( '.fontred_pwd' ).html( '密码不能为空' );
        $( this ).parent().addClass( 'active' );
        $msgbox.addClass( 'active' ).find( '.error_text .text' ).text( '密码不能为空' );
      } else {
        if ( $( this ).val().length < 6 ) {
          $( this ).siblings( '.pwd_right' ).hide();
          $( this ).siblings( '.fontred_pwd' ).html( '输入的密码格式有误' );
          $msgbox.addClass( 'active' ).find( '.error_text .text' ).text( '输入的密码格式有误' );
        } else {
          $( this ).siblings( '.fontred_pwd' ).html( '' );
          $( this ).siblings( '.pwd_right' ).show();
          $msgbox.removeClass( 'active' );
          $( this ).parent().removeClass( 'error' );
        }
      }
    } );
    //邀请码键盘检测
    $( '.user_invitation' ).focus( function() {
      $( '.content-wrap' ).addClass( 'active' );
    } ).blur( function() {
      $( '.content-wrap' ).removeClass( 'active' );
      var $msgbox = $( this ).parent().addClass( 'error' ).next().removeClass( 'active msg' );
      var $_box = $( this ).parent();
      if ( $( this ).val() == '' ) {
        $( '.fontred_invitation' ).html( '邀请码不能为空' );
        $( '.verify_right' ).hide();
        $msgbox.addClass( 'active' ).find( '.error_text .text' ).text( '邀请码不能为空' );
      } else {
        $.ajax( {
          type: "POST", //用POST方式传输
          dataType: 'text',
          url: BIGWE_API.REGISTER.INVITATION_VERIFY, //目标地址
          data: {
            user_invitation: $( '.user_invitation' ).val()
          },
          error: function() {
            ShowTitleMessage.showWarning( '输入的邀请码有误', showTime );
          },
          success: function( msg ) {
            switch ( msg ) {
              case 'error_invitation_null':
                $( '.fontred_invitation' ).html( '邀请码无效' );
                $( '.invitation_right' ).hide();
                $msgbox.addClass( 'active' ).find( '.error_text .text' ).text( '邀请码无效' );
                break;
              case 'error_invitation_invalid':
                $( '.fontred_invitation' ).html( '邀请码失效' );
                $( '.invitation_right' ).hide();
                $msgbox.addClass( 'active' ).find( '.error_text .text' ).text( '邀请码失效' );
                break;
              default:
                $( '.invitation_right' ).show();
                $( '.fontred_invitation' ).html( '' );
                $msgbox.removeClass( 'active' );
                $_box.removeClass( 'error' );
            }
          }
        } );
      }
    } );
    /*$('.user_invitation').keyup(function(){
        if($(this).val()==''){
            $(this).siblings('.invitation_right').hide();
            $(this).siblings('.fontred_invitation').html('');
        }else{
            $(this).siblings('.fontred_invitation').html('');
        }
    });*/
    //行业选择内容的检测
    $( '.field-title-choice' ).click( function() {
      $( '.fontred-field-choice' ).html( '' );
    } );

  } );

  //验证码发送
  var InterValObj; //timer变量，控制时间
  var count = 60; //间隔函数，1秒执行
  var curCount; //当前剩余秒数
  function sendMessage() {
    var page_token = $( 'input#page_token' ).val();
    var $msgbox = $( '.ipt_phone_msg' );
    if ( re.test( $( '#user_phone' ).val() ) || emailRe.test( $( '#user_phone' ).val() ) ) {
      $( '.fontred_phone' ).html( '' );
      $msgbox.removeClass( 'active' );
      //设置button效果，开始计时
      if ( $( '#user_phone' ).val().indexOf( '@' ) != -1 ) {
        $.ajax( {
          type: "POST", //用POST方式传输
          dataType: 'text',
          url: BIGWE_API.REGISTER.EMAIL_VERIFY, //目标地址
          data: {
            user_email: $( '#user_phone' ).val()
          },
          error: function() {
            ShowTitleMessage.showWarning( '邮箱查询失败', showTime );
          },
          success: function( msg ) {
            if ( msg == 'success' ) {
              $( '.fontred_phone' ).html( '' );
              $msgbox.removeClass( 'active' );
              $( ".get-code" ).attr( "disabled", "true" );
              $.ajax( {
                type: "POST", //用POST方式传输
                dataType: "text", //数据格式
                url: BIGWE_API.REGISTER.SEND_MAIL, //目标地址
                data: {
                  user_email: $( '#user_phone' ).val()
                },
                error: function( msg ) {
                  ShowTitleMessage.showWarning( '发送失败', showTime );
                },
                success: function( msg ) {
                  if ( msg == 'email_over' ) {
                    ShowTitleMessage.showWarning( '今日邮箱验证已用完', showTime );
                    $( ".get-code" ).removeAttr( "disabled" );
                  } else if ( msg == 'error_send' ) {
                    curCount = count;
                    $( ".get-code" ).val( curCount + "s后重新获取" );
                    InterValObj = window.setInterval( SetRemainTime, 1000 );
                    ShowTitleMessage.showWarning( '邮件发送失败', showTime );
                  } else if ( msg == 'success' ) {
                    curCount = count;
                    $( ".get-code" ).val( curCount + "s后重新获取" );
                    InterValObj = window.setInterval( SetRemainTime, 1000 );
                    ShowTitleMessage.show( '邮件发送成功', showTime );
                  } else if ( msg == 'error_email' ) {
                    curCount = count;
                    $( ".get-code" ).val( curCount + "s后重新获取" );
                    InterValObj = window.setInterval( SetRemainTime, 1000 );
                    ShowTitleMessage.showWarning( '邮件发送失败，邮件地址错误', showTime );
                  } else if ( msg.indexOf( "time" ) >= 0 ) {
                    curCount = msg.substring( 4 );
                    $( ".get-code" ).val( msg.substring( 4 ) + "s后重新获取" );
                    InterValObj = window.setInterval( SetRemainTime, 1000 );
                    ShowTitleMessage.showWarning( '操作频繁，请稍后在试', showTime );
                    $( ".register > button" ).attr( "disabled", "disabled" );
                  } else {
                    curCount = count;
                    $( ".get-code" ).val( curCount + "s后重新获取" );
                    InterValObj = window.setInterval( SetRemainTime, 1000 );
                    ShowTitleMessage.showWarning( '邮件发送失败，邮件地址错误', showTime );
                  }
                }
              } );
            } else {
              $( '.fontred_phone' ).html( '该邮箱已注册' );
              $( '.phone_right' ).hide();
              $msgbox.addClass( 'active' ).find( '.text' ).text( '该邮箱已注册' );
            }
          }
        } );
      } else {
        $.ajax( {
          type: "POST", //用POST方式传输
          dataType: "text", //数据格式
          url: BIGWE_API.REGISTER.PHONE_VERIFY, //目标地址
          data: {
            user_phone: $( '#user_phone' ).val()
          },
          error: function() {
            ShowTitleMessage.showWarning( '手机号查询失败', showTime );
          },
          success: function( msg ) {
            if ( msg == 'success' ) {
              $( '.fontred_phone' ).html( '' );
              $( ".get-code" ).attr( "disabled", "true" );
              $msgbox.removeClass( 'active' );
              //向后台发送处理数据
              $.ajax( {
                type: "POST", //用POST方式传输
                dataType: "json", //数据格式
                url: BIGWE_API.REGISTER.SEND_MESSAGE, //目标地址
                data: {
                  phone: $( '#user_phone' ).val(),
                  //sms_token:page_token,
                  verify: $( '#img_verify_code' ).val(),
                  page: 'register'
                },
                error: function( data ) {
                  ShowTitleMessage.showWarning( '发送失败', showTime );
                },
                success: function( data ) {
                  switch ( data.ret ) {
                    case 41000:
                      //图片验证码错误ok
                      $( ".get-code" ).removeAttr( "disabled" );
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( ".verify_img img" ).attr( "src", "/RegisterPage/captcha" );
                      break;
                    case 41001:
                      //请填写图片验证码ok
                      $( '#img_validate' ).modal( 'show' );
                      $( ".get-code" ).removeAttr( "disabled" );
                      //ShowTitleMessage.showWarning('请填写图片验证码', showTime);
                      break;
                    case 41003:
                      //今日短信验证码条数已用完ok
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( ".get-code" ).removeAttr( "disabled" );
                      $( '#img_verify_code' ).val( '' );
                      break;
                    case 41004:
                      //短信发送失败
                      curCount = count;
                      $( ".get-code" ).val( curCount + "s后重新获取" );
                      InterValObj = window.setInterval( SetRemainTime, 1000 );
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( '#img_verify_code' ).val( '' );
                      break;
                    case 0:
                      //发送成功
                      curCount = count;
                      $( ".get-code" ).val( curCount + "s后重新获取" );
                      InterValObj = window.setInterval( SetRemainTime, 1000 );
                      ShowTitleMessage.show( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( '#img_verify_code' ).val( '' );
                      $( ".verify_img img" ).attr( "src", "/RegisterPage/captcha" );
                      break;
                    case 41006:
                      //该手机号已被注册
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( ".get-code" ).removeAttr( "disabled" );
                      $( '#img_verify_code' ).val( '' );
                      break;
                    default:
                      //操作频繁，请稍后再试ok
                      curCount = data.data;
                      $( ".get-code" ).val( data.data + "s后重新获取" );
                      InterValObj = window.setInterval( SetRemainTime, 1000 );
                      ShowTitleMessage.showWarning( data.msg, showTime );
                      $( '#img_validate' ).modal( 'hide' );
                      $( ".register > button" ).attr( "disabled", "disabled" );
                      $( '#img_verify_code' ).val( '' );
                      break;
                  }
                }
              } );
            } else {
              $( '.phone_right' ).hide();
              $( '.fontred_phone' ).html( '该手机号已注册' );
              $msgbox.addClass( 'active' ).find( '.text' ).text( '该手机号已注册' );
            }
          }
        } );
      }

    } else {
      $( '.fontred_phone' ).html( '输入的手机号 / 邮箱有误' );
      $msgbox.addClass( 'active' ).find( '.text' ).text( '输入的手机号 / 邮箱有误' );
    }
  }
  $( '.get-code' ).click( function() {
    sendMessage();
  } );
  $( '#img_validate .btn-success' ).click( function() {
    if ( $( '#img_verify_code' ).val() == '' ) {
      ShowTitleMessage.showWarning( '请填写图片验证码', showTime );
      return;
    }
    sendMessage();
  } );
  $( '#img_validate .btn-default' ).click( function() {
    $( '#img_verify_code' ).val( '' );
  } );
  //timer处理函数
  function SetRemainTime() {
    if ( curCount == 0 ) {
      window.clearInterval( InterValObj ); //停止计时器
      $( ".get-code" ).removeAttr( "disabled" ); //启用按钮
      $( ".get-code" ).val( "重新获取验证码" );
    } else {
      curCount--;
      $( ".get-code" ).val( curCount + "s后重新获取" );
    }
  }

  //设置Cookie
  function setCookie( name, value ) {
    var Days = 30;
    var exp = new Date();
    exp.setTime( exp.getTime() + Days * 24 * 60 * 60 * 1000 );
    document.cookie = name + "=" + escape( value ) + ";expires=" + exp.toGMTString();
  }

  //获取Cookie
  function getCookie( name ) {
    var arr, reg = new RegExp( "(^| )" + name + "=([^;]*)(;|$)" );
    if ( arr = document.cookie.match( reg ) )
      return unescape( arr[ 2 ] );
    else
      return null;
  }

  //清除Cookie
  function delCookie( name ) {
    var exp = new Date();
    exp.setTime( exp.getTime() - 1 );
    var cval = getCookie( name );
    if ( cval != null )
      document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  }

  //删除所有cookie
  function clearCookie() {
    var keys = document.cookie.match( /[^ =;]+(?=\=)/g );
    if ( keys ) {
      for ( var i = keys.length; i--; )
        document.cookie = keys[ i ] + '=0;expires=' + new Date( 0 ).toUTCString()
    }
  }

  //中文字为2个字符
  function chkstrlen( str ) {
    var strlen = 0;
    for ( var i = 0; i < str.length; i++ ) {
      if ( str.charCodeAt( i ) > 255 ) {
        strlen += 2; //如果是汉字，则字符串长度加2
      } else {
        strlen++;
      }
    }
    return strlen;
  }

} )
